package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsSystemInfo;
import com.ruoyi.system.domain.news.query.NewsSystemInfoQuery;
import com.ruoyi.system.domain.news.vo.NewsSystemInfoVo;
import com.ruoyi.system.service.news.NewsSystemInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsSystemInfo")
@Api(value = "newsSystemInfoApiController", tags  = "系统信息Api")
public class NewsSystemInfoApiController extends BaseController {

	@Resource
	private NewsSystemInfoService newsSystemInfoService;

	@ApiOperation(value = "获取单个系统信息信息", notes = "获取单个系统信息信息")
	@GetMapping("/getById")
	public R<NewsSystemInfo> getById(@RequestParam(value = "id") Long id) {
		NewsSystemInfoQuery newsSystemInfoQuery = new NewsSystemInfoQuery();
		newsSystemInfoQuery.setId(id);
		List<NewsSystemInfoVo> newsSystemInfoList = newsSystemInfoService.getNewsSystemInfoList(newsSystemInfoQuery);
		if (newsSystemInfoList!=null&&newsSystemInfoList.size()>0) {
			return R.ok(newsSystemInfoList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取系统信息信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsSystemInfoVo>> list(@RequestBody NewsSystemInfoQuery newsSystemInfoQuery) {
        newsSystemInfoQuery.setIsEnable("1");
		List<NewsSystemInfoVo> newsSystemInfoList = newsSystemInfoService.getNewsSystemInfoList(newsSystemInfoQuery);
		return R.ok(new PageInfo<>(newsSystemInfoList));
	}
}
